#include<iostream>
#include<algorithm>
using namespace std;
int ans=0;
void change(int a[], int n)
{
	int left, right;
	ans++;
	left = right = n/2;
	n%2 == 1? right = right+2: right  = right+1;
	while (left > 0)
	{
		swap(a[left--], a[right++]);
	}
}
int main()
{
	int n;
	cin >> n;
	int a[n+1];
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	while (n > 1)
	{
		int k = 1;
		for (int i = 2; i <= n; i++)
		{
			if (a[k] < a[i]) k=i;
		}
		if (k != n)
		{
			if (k > 1)
			{
				change(a, k);
			}
			change(a, n);
		}
		n--;
	}
	cout << ans << endl;
	return 0;
}
